package com.tgy.leetcode;

import java.util.Stack;

/**
 * @Author: tgy
 * @Date: 12/3/20 11:22 AM
 *
 * https://leetcode-cn.com/problems/daily-temperatures/
 */
public class _739_每日温度_01 {

    public int[] dailyTemperatures(int[] T) {

        if (T == null || T.length == 0) {

            return new int[0];
        }

        int[] ret = new int[T.length];

        for (int i = T.length - 2; i >= 0 ; i--) {

            if (T[i] < T[i + 1]) {

                ret[i]  = 1;
            }else{

                int index = i+1 + ret[i + 1];
                while (index < T.length) {

                    //[34,80,80,34,34,80,80,80,80,34]
                    if (T[i] < T[index]) {

                        ret[i] = index - i;
                        break;
                    }else {

                        if (ret[index] == 0) {

                            break;
                        }
                    }
                    index = index + ret[index];
                }
            }
        }

        return ret;
    }
}
